package com.mail.controller;

import com.mail.common.DataResult;
import com.mail.enums.ResponseCode;
import com.mail.service.UserService;
import io.minio.errors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("/user/file")
public class UploadController {
    @Autowired
    private UserService userService;

    @PostMapping("/upload")
    public DataResult uploadImg(MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        if(file==null||file.isEmpty()||file.getSize()==0){
            return DataResult.error(ResponseCode.FILE_IS_NOT_NULL.getMsg());
        }
        return userService.uploadImg(file);
    }
}
